//
//  StatusOriginalView.swift
//  SinaWeibo
//
//  Created by Apple on 15/11/14.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
import SDWebImage
class StatusOriginalView: UIView {
    var status: Status?{
        didSet {
            iconImage.sd_setImageWithURL(status?.user?.headImageURL, placeholderImage: UIImage(named: "avatar_default_big"))
            nameLabel.text = status?.user?.name
            memberIconView.image = status?.user?.mbrankImage
            verifiedIconView.image = status?.user?.verified_type_Image
            timeLabel.text = "11:11"
            sourceLabel.text = "来自黑马微博"
            contentLabel.text = status?.text
            pictureView.imageURLs = status?.imageURLs
        }
    }
    
    
    //MARK: 3.重写父类的构造方法 调用设置UI
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK:2.设置UI
    private func setupUI(){
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(iconImage)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(verifiedIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        
        //设置约束
        iconImage.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top).offset(StatusCellMargin)
            make.left.equalTo(snp_left).offset(StatusCellMargin)
            make.width.equalTo(StatusCellIconWidth)
            make.height.equalTo(StatusCellIconWidth)
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconImage.snp_right).offset(StatusCellMargin)
            make.top.equalTo(iconImage.snp_top)
        }
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
            make.top.equalTo(nameLabel.snp_top)
        }
        verifiedIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconImage.snp_centerX)
            make.centerY.equalTo(iconImage.snp_centerY)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconImage.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(iconImage.snp_bottom)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(timeLabel.snp_bottom)
        }
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImage.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(iconImage)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentLabel.snp_left)
//            make.width.equalTo(100)
//            make.height.equalTo(100)
        }
        //注:没有加这条约束的话 会出现cell重叠,因为本身view的高度不能确定
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin)
        }
        
    }
    
    //MARK:1.懒加载控件
    private lazy var iconImage:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var nameLabel: UILabel = UILabel(title: "一个人的歌IOS", size: 14, color: UIColor.darkGrayColor())
    //认证用户类型
    private lazy var verifiedIconView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    //用户等级
    private lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    //发布时间
    private lazy var timeLabel:UILabel = UILabel(title: "11:11", size: 10, color: themeColor)
    //微博来源
    private lazy var sourceLabel: UILabel = UILabel(title: "来自黑马微博", size: 10, color: UIColor.lightGrayColor())
    //微博正文
    private lazy var contentLabel: UILabel = UILabel(title: "老板来碗鱼丸粗面..木有粗面; 那来碗鱼丸河粉..木有鱼丸;是吗。。。那牛肚粗面吧..没有粗面;", size: 14, color: UIColor.lightGrayColor(), margin: StatusCellMargin)
    private lazy var pictureView: StatusPictureView = StatusPictureView()
}
